<template>
  <wm-order-std :enable-accessory-pack-download="enableAccessoryPackDownload" ref="decRef">
    <template v-slot:btn="props">
      <q-btn :disable="props.data.submittingState" @click="manuallyDeliverPickRbTask(props.data.itemId)" color="primary" label="下发拣货任务"
        v-if="props.data.form.bizType === 'SAP出库' && ((props.data.form.orderState === '11') || (props.data.form.orderState === '12') || (props.data.form.orderState === '21'))"/>
    </template>
  </wm-order-std>
</template>
<script lang="ts" setup>
import WmOrderStd from '@njt/wms/pages/work/Order.vue'
import { ref } from 'vue';
const enableAccessoryPackDownload = $f.globalCfg.enableAccessoryPackDownload

let decRef = ref<any>()

const manuallyDeliverPickRbTask = (itemId: string) => {
  void $f.ui.messageBox({
    caption: '操作确认',
    text: '确定要人工下发WCS拣货任务吗?',
    icon: 'Question',
    buttons: 'OkCancel',
    delayClose: true,
  }).then((btn) => {
    if (btn === 'ok') {
      $f.axios
        .post('/project/mhlbc/work/order/manually-deliver-pick-rb-tasks/' + itemId)
        .then(() => {
          $f.ui.closeMsgBox()
          decRef.value.loadModelData()
        })
        .catch((err) => {
          void $f.ui.messageBox({
            caption: '下发拣货任务',
            text: $f.getAxiosErrMsg(err),
            icon: $f.getAxiosErrIcon(err),
            buttons: 'Close',
          })
        })
    }
  })
}

</script>
